﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dbPoll_Application.ViewModels.EditParticipantsViewModel>" %>

<% using (Ajax.BeginForm("SaveList", "Participant", null, new AjaxOptions { OnSuccess = "disableSave" }, null))
   { %>
   <%= Html.HiddenFor(m => m.PollID)%>
   <%= Html.HiddenFor(m => m.PollName)%>
   <%= Html.HiddenFor(m => m.isGroup)%>
<div style="overflow:auto;max-height:600px">
<div class="left">
<table class="editParticipant">
    <thead>
        <tr id="headering">
            <th style="min-width:5px">Device ID</th>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
    </thead>
    <tbody>
        <% for (var i = 0; i < Model.Participants.Count; i++)
           { %>
           <tr class="editParticipantRow">
               <td style="min-width:5px"><%= Html.HiddenFor(m => m.Participants[i].ParticipantID)%><%= Html.TextBoxFor(m => m.Participants[i].DeviceID, new { style="width:60px" })%></td>
               <td><%= Html.TextBoxFor(m => m.Participants[i].FirstName, new { style = "width:130px" })%></td>
               <td><%= Html.TextBoxFor(m => m.Participants[i].LastName, new { style = "width:130px" })%></td>
           </tr>
        <% } %>
    </tbody>
</table>
</div>
<div id="editParticipantFields">
<table class="editParticipant" style="overflow:auto">
    <thead>
        <tr id="headering">
            <% int a = 0;
               foreach (var field in Model.Fields)
               {%>
               <th id="<%=field.fieldID %>"><%=field.name %>
               <input type="hidden" id="dem<%=field.fieldID%>" value="<%=Model.hasdem[a]%>"/>
               <input type="hidden" id="com<%=field.fieldID%>" value="<%=Model.hascom[a]%>"/>
               <button onclick="deleting(<%=field.fieldID %>)" class="deleteField">Delete</button></th>
               <%a++;} %>
            <th>Voting Weight</th>
            <th>Entity</th>
        </tr>
    </thead>
    <tbody>
        <% for (var i = 0; i < Model.Participants.Count; i++)
           { %>
           <tr class="editParticipantRow">
               <% for (var j = 0; j < Model.Participants[i].Fields.Count; j++)
                  { %>
                  <td><%= Html.HiddenFor(m => m.Participants[i].Fields[j].FieldID)%><%= Html.TextBoxFor(m => m.Participants[i].Fields[j].Value)%></td>
               <% } %>
               <td><%= Html.DropDownListFor(m => m.Participants[i].VotingWeight, new SelectList(Enumerable.Range(1, 100), Model.Participants[i].VotingWeight)) %></td>
               <td><%= Html.DropDownListFor(m => m.Participants[i].Entity.entityID, new SelectList(Model.Entities, "entityID", "name", Model.Participants[i].Entity.entityID))%></td>
           </tr>
        <% } %>
    </tbody>
</table>
</div>
</div>
<div>
    <input type="submit" id="submitEditList" value="Save" />
</div>
<% } %>
</div>